﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RelationExpertSystem.Relation
{
    public class Grandparent : RelationBase
    {
        private static Grandparent _singleton = new Grandparent();
        public static Grandparent Instance
        {
            get { return _singleton; }
        }

        private Grandparent() { }

        public override bool IsRelated(Person a, Person b)
        {
            // b is a's grandparent IFF b is a parent of one of a's parents
            return (!Person.IsNull(a.Father) && (b == a.Father.Father || b == a.Father.Mother)) ||
                (!Person.IsNull(a.Mother) && (b == a.Mother.Father || b == a.Mother.Mother));
        }

        public override IEnumerable<IRelation> GetDependencies()
        {
            return new HashSet<IRelation>(new IRelation[] { Mother.Instance, Father.Instance });
        }
    }
}
